package com.findme.fecedetection.adapter

import android.support.v7.widget.RecyclerView
import com.findme.fecedetection.Const
import com.findme.fecedetection.R
import com.findme.fecedetection.base.ImageViewTang
import com.findme.fecedetection.base.JustAdapter
import com.findme.fecedetection.bean.PetListBean
import com.findme.fecedetection.ui.activity.PatDetailsActivity
import com.findme.fecedetection.utlis.getStringType
import com.tanguy.user.utlis.extend.click
import com.tanguy.user.utlis.extend.setText
import com.tanguy.user.utlis.extend.toTimeString
import org.jetbrains.anko.find
import org.jetbrains.anko.startActivity

/**
 * Created by dab on 2017/11/19 0019 16:19
 */
class HomeAdapter(data: ArrayList<PetListBean>) : JustAdapter<PetListBean>(data, R.layout.item_home) {
    override fun bind(holder: RecyclerView.ViewHolder, position: Int, data: java.util.ArrayList<PetListBean>) {
        val petListBean = data[position]
        holder.itemView.apply {
//            setText(R.id.tv_name,)
            setText(R.id.tv_find, getStringType(Const.Type.FBLX,petListBean.type)?: "null")
            find<ImageViewTang>(R.id.iv_icon).setImageURI(petListBean.cover)
            setText(R.id.tv_time, petListBean.createTime.toTimeString("yyyy/MM/dd"))
            setText(R.id.tv_location, petListBean.location ?: "null")
            setText(R.id.tv_color, "颜色:" + getStringType(Const.Type.CWYS,petListBean.color))
            setText(R.id.view, "大小:${getStringType(Const.Type.CWDX, petListBean.size)} 性别: ${getStringType(Const.Type.CWXB, petListBean.gender)}")
        }
        click(holder.itemView) {
            holder.itemView.context.startActivity<PatDetailsActivity>("id" to petListBean.id)
        }
    }

}